package org.meichao.config;

import org.meichao.interceptor.AccessInterceptor;
import org.meichao.interceptor.VerifyTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 配置拦截器,解决跨域问题
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Autowired
    AccessInterceptor accessInterceptor;

    @Autowired
    VerifyTokenInterceptor verifyTokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //跨域
        registry.addInterceptor(accessInterceptor)
                .addPathPatterns("/**");//指定特定路径,如/hello,表明只有/hello请求能被拦截器拦截,这里/**表明所有请求都拦截
          //    .excludePathPatterns("/hello");//排除特定路径,如/hello,配合/**使用表明只有/hello请求不会被拦截,即/hello请求不走拦截器

        //token校验
        //registry.addInterceptor(verifyTokenInterceptor)
          //      .addPathPatterns("/**");
    }
}
